package com.bambooshoot.controller.biz;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bambooshoot.common.annotation.Log;
import com.bambooshoot.common.annotation.RepeatSubmit;
import com.bambooshoot.common.core.controller.BaseController;
import com.bambooshoot.common.core.domain.R;
import com.bambooshoot.common.core.page.PageQuery;
import com.bambooshoot.common.core.page.TableDataInfo;
import com.bambooshoot.common.enums.BusinessType;
import com.bambooshoot.common.utils.ExcelUtil;
import com.bambooshoot.common.validate.AddGroup;
import com.bambooshoot.common.validate.EditGroup;
import com.bambooshoot.domain.bo.BizTravelDetailsBo;
import com.bambooshoot.domain.vo.BizTravelDetailsVo;
import com.bambooshoot.service.BizTravelDetailsService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 旅游明细
 *
 * @author mxc
 * @date 2024-07-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/biz/travelDetails")
public class BizTravelDetailsController extends BaseController {

    private final BizTravelDetailsService bizTravelDetailsService;

    /**
     * 查询旅游明细列表
     */
    @SaCheckPermission("biz:travelDetails:list")
    @GetMapping("/list")
    public TableDataInfo<BizTravelDetailsVo> list(BizTravelDetailsBo bo, PageQuery pageQuery) {
        return bizTravelDetailsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出旅游明细列表
     */
    @SaCheckPermission("biz:travelDetails:export")
    @Log(title = "旅游明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BizTravelDetailsBo bo, HttpServletResponse response) {
        List<BizTravelDetailsVo> list = bizTravelDetailsService.queryList(bo);
        ExcelUtil.exportExcel(list, "旅游明细", BizTravelDetailsVo.class, response);
    }

    /**
     * 获取旅游明细详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("biz:travelDetails:query")
    @GetMapping("/{id}")
    public R<BizTravelDetailsVo> getInfo(@NotNull(message = "主键不能为空")
                                         @PathVariable Long id) {
        return R.ok(bizTravelDetailsService.queryById(id));
    }

    /**
     * 新增旅游明细
     */
    @SaCheckPermission("biz:travelDetails:add")
    @Log(title = "旅游明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BizTravelDetailsBo bo) {
        return toAjax(bizTravelDetailsService.insertByBo(bo));
    }

    /**
     * 修改旅游明细
     */
    @SaCheckPermission("biz:travelDetails:edit")
    @Log(title = "旅游明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BizTravelDetailsBo bo) {
        return toAjax(bizTravelDetailsService.updateByBo(bo));
    }

    /**
     * 删除旅游明细
     *
     * @param ids 主键串
     */
    @SaCheckPermission("biz:travelDetails:remove")
    @Log(title = "旅游明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(bizTravelDetailsService.deleteWithValidByIds(List.of(ids), true));
    }
}
